#!/usr/bin/env python
# -*- coding:utf8 -*-
from core import base


class Teacher(base.BaseClass):
    def __init__(self, teacher_name, teacher_salary, teacher_school):
        base.BaseClass.__init__(self)
        self.teacher_name = teacher_name
        self.teacher_salary = teacher_salary
        self.teacher_school = teacher_school

    def create_class_record(self):
        class_record = []
        student_school = input("选择学校：")
        student_classes = input("选择班级：")
        student_times = input("课次：")
        student_list = base.BaseClass.open_file(self, "student")
        for i in student_list:
            if i["学校"] == student_school and i["班级"] == student_classes:
                student_name = i["姓名"]
                student_status = input("%s 上课情况：" % student_name)
                i["上课情况"] = student_status
                i["课次"] = student_times
                class_record.append(i)
        base.BaseClass.seek_list(self, "class_record", class_record)

    def create_class_grade(self):
        class_grade = []
        student_school = input("选择学校：")
        student_class = input("选择班级：")
        student_times = input("课次：")
        student_list = base.BaseClass.open_file(self,"student")
        for i in student_list:
            if i["学校"] == student_school and i["班级"] == student_class:
                student_name = i["姓名"]
                student_grade = input("%s 成绩：" % student_name)
                i["成绩"] = student_grade
                i["课次"] = student_times
                class_grade.append(i)
        base.BaseClass.seek_list(self, "class_grade", class_grade)

    def teacher_view_grade(self):
        grade_list = []
        student_school = input("校名：")
        student_class = input("班级：")
        student_times = input("课次：")
        class_grade_list = base.BaseClass.open_file(self,"class_grade")
        for i in class_grade_list:
            for j in i:
                if j["学校"] == student_school and j["班级"] == student_class and j["课次"] == student_times:
                    grade_list.append(j)
        for i in grade_list:
            for key in i:
                print(key,i[key])
            print("\n")

    def teacher_view_record(self):
        record_list = []
        student_school = input("校名：")
        student_class = input("班级：")
        student_time = input("课次：")
        class_record_list = base.BaseClass.open_file(self,"class_record")
        for i in class_record_list:
            for j in i:
                if j["学校"] == student_school and j["班级"] == student_class and j["课次"] == student_time:
                    record_list.append(j)
        for i in record_list:
            for key in i:
                print(key, i[key])
            print("\n")


class Teacher_view(Teacher):
    def __init__(self, teacher_name, teacher_salary, teacher_school):
        Teacher.__init__(self, teacher_name, teacher_salary, teacher_school)

    def login(self):
        menu = u"""
        ------欢迎进入讲师视图------
            \033[32;1m 1、创建上课记录
            2、创建学员成绩
            3、查看学员上课记录
            4、查看学员成绩
            5、返回
            \033[0m
        """
        menu_dic = {
            '1': Teacher.create_class_record,
            '2': Teacher.create_class_grade,
            '3': Teacher.teacher_view_record,
            '4': Teacher.teacher_view_grade,
            '5': "logout"
        }
        if True:
            exit_flag = False
            while not exit_flag:
                print(menu)
                option = input("请选择：").strip()
                if option in menu_dic:
                    if int(option) == 5:
                        exit_flag = True
                    else:
                        print(menu_dic[option])
                        menu_dic[option](self)
                else:
                    print("\033[31;1m输入错误，重新输入\033[0m")
